<template>
    <Modal v-model="visible" title="查验例外设置" width="600" :key="key">
        <Form ref="formData" :model="formData" :label-width="150" :rules="errorrules">
            <FormItem label="例外类型:" prop="pshr0006">
                <dictSelect :sel_val='formData.pshr0006' dictCode="pshr_exception"
                            :bindData.sync="formData.pshr0006" style="width: 300px" clearable/>
                <br/>
            </FormItem>
            <FormItem label="例外说明:" prop="pshr0007">
                <Input v-model="formData.pshr0007" type="textarea" maxlength="100" show-word-limit :rows="3" style="width: 300px"/>
            </FormItem>
        </Form>
        <div slot="footer">
            <Button type="text" size="large" @click="visible = false">取消</Button>
            <template>
                <Button type="primary" size="large" @click="handleErrorSubmit('formData')">确定</Button>
            </template>
        </div>
    </Modal>
</template>

<script>
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import dictSelect from '@/components/dictSelect/dictSelect.vue'
    import { postAction } from '@/api/request'
    export default {
        mixins: [CommonMixin],
        name: "exception-deal",
      components: {
        dictSelect,
      },
        data() {
            return {
                visible: false,
                title: "查验例外设置",
                key: "",
                Loading: false,
                queryParam: {},
                url: {
                    deal: "/api/ac/subsistence/ss00005Service/createHandleErrorException"
                },
              errorrules: {
                pshr0006: [
                  {required: true, message: '请输入例外类型', trigger: 'blur'}
                ],
                pshr0007: [
                  {required: true, message: '请输入例外说明', trigger: 'blur'}
                ]
              },
              formData: {},
              fieldsToErrorValidate: ["pshr0006", "pshr0007"],

            }
        },
        methods: {
            edit(row) {
              let that = this
              that.$refs['formData'].resetFields()
              that.visible = true
              that.formData = Object.assign({}, row)
            },
            cancel() {
                this.visible = false;
            },
          //处理设置例外
          handleErrorSubmit(name) {
            let that = this;
            let validate = true;
            let err_msg = [];
            for (let item of that.fieldsToErrorValidate) {
              that.$refs[name].validateField(item, (error) => {
                if (error) {
                  validate = false;
                  err_msg.push(that.errorrules[item][0].message);
                }
              })
            }
            if (validate) {
              let url = this.url.deal;
              postAction(url, this.formData).then((res) => {
                if (res.data.errcode != 0) {
                  this.$Message.error(res.data.errmsg);
                } else {
                  this.$Message.success("操作成功");
                  this.visible = false;
                  this.$emit('refreshPageData');
                }
              }).finally(() => {
                that.Loading = false;
              });
            }else{
              this.$Message.error(err_msg[0]);
            }

          },
        }
    }
</script>

<style scoped>

</style>
